local tianming = fk.CreateSkill {

  name = "joy__tianming",

  tags = {  },

}



tianming:addEffect(fk.TargetConfirmed, {
  name = "joy__tianming",
  anim_type = "defensive",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(tianming.name) and data.card.trueName == "slash"
  end,
  on_cost = function(self, event, target, player, data)
    local ids = table.filter(player:getCardIds("he"), function(id) return not player:prohibitDiscard(Fk:getCardById(id)) end)
    if #ids < 3 then
      if player.room:askForSkillInvoke(player, tianming.name, data, "#tianming-cost") then
        event:setCostData(self, ids)
        return true
      end
    else
      local cards = player.room:askForDiscard(player, 2, 2, true, tianming.name, true, ".", "#tianming-cost", true)
      if #cards > 0 then
        event:setCostData(self, cards)
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self), tianming.name, player, player)
    if not player.dead then
      player:drawCards(2, tianming.name)
    end
    local targets = table.map(table.filter(room.alive_players, function(p) return not p:isAllNude() end), Util.IdMapper)
    local to = room:askForChoosePlayers(player,targets,1,1,"#joy__tianming",tianming.name,true)
    if #to > 0 then
    local p = room:getPlayerById(to[1])
    local ids = table.filter(p:getCardIds("he"), function(id) return not p:prohibitDiscard(Fk:getCardById(id)) end)
    local n = math.min(#ids,2)
    if ids == 0 then
      if room:askForSkillInvoke(p, tianming.name, data, "#tianming-cost") then
        player.room:drawCards(p,2, tianming.name)
      end
    else
      local cards = room:askForDiscard(p, n, 2, true, tianming.name, false, ".", "#tianming-cost")
      if #cards > 0 and not p.dead then
        room:drawCards(p, 2, tianming.name)
      end
    end
    end
  end,
})

return tianming